package qlttn.dao.daointerface;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import qlttn.common.utility.HibernateUtility;
import qlttn.model.Question;

public class QuestionDAOImpl implements QuestionDAO{
	  private Session getSession()
	  {
	  Session s =null;
	     try{
		 		
	 		s=HibernateUtility.getSessionFactory().openSession();
	 		}catch(HibernateException e){
					System.out.println(e.getMessage());
	}
		   return s;
	  }

	@Override
	public boolean save(Question question) {
		Session session =getSession();
 		Transaction tx= session.beginTransaction();
		boolean result = false;
		try {
			tx = session.beginTransaction();
			// do some work
			session.saveOrUpdate(question);
			tx.commit();
			result = true;
		} catch (RuntimeException e) {
			if (tx != null) {
				tx.rollback();
				result = false;
			}
			throw e; // or display error message
		} finally {
			session.close();
		}
		return result;
	}
	

}
